package com.an.vhr.service;

import com.an.vhr.bean.Role;
import com.an.vhr.mapper.RoleMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: an1089
 **/
@Service
public class RoleService {
    @Resource
    RoleMapper roleMapper;

    public List<Role> getALlRoles() {
        return roleMapper.getALlRoles();
    }

    public int addRole(Role role) {
        if(!role.getName().startsWith("ROLE_"))
        {
            role.setName("ROLE_"+role.getName());
        }
        return roleMapper.insertSelective(role);
    }

    @Transactional
    public int deleteRole(Integer id) {
        return roleMapper.deleteByPrimaryKey(id);
    }
}
